package com.loveweinuo.util;

import com.google.gson.Gson;
import com.loveweinuo.bean.RequestPayBean;
import com.loveweinuo.bean.ToLoginBean;
import com.lzy.okgo.callback.StringCallback;

import static com.lzy.okgo.OkGo.post;

/**
 * Created by 86178 on 2019/8/9.
 * author mogen
 * 用心，成就一切。
 */

public class HTTPAPI {

    public static HTTPAPI instance;

    private static Gson gson = null;

    public static HTTPAPI getInstance() {
        if (instance == null) {
            instance = new HTTPAPI();
        }
        if (gson == null) {
            gson = new Gson();
        }
        return instance;
    }

    public void login(String url,String phone, String pwd, String registionId, StringCallback callback) {
        ToLoginBean bean = new ToLoginBean();
        bean.setParams(new ToLoginBean.ParamsBean(phone, pwd, registionId));
        post(url)
                .tag(this)
                .headers("type", "2")
                .connTimeOut(30000)
                .upJson(gson.toJson(bean))
                .execute(callback);
    }

    public void pay(String token ,String userId,String url,StringCallback callback){
        RequestPayBean bean = new RequestPayBean();
        bean.setParams(new RequestPayBean.ParamsBean("10","0.01","2","0"));
        post(url)
                .tag(this)
                .headers("type", "2")
                .headers("token", token)
                .headers("userId", userId)
                .connTimeOut(30000)
                .upJson(gson.toJson(bean))
                .execute(callback);
    }

}


